<?php
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                         |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: anguolei@clcw.com.cn                                           |
// +------------------------------------------------------------------------+
//

namespace AuctionCore\CarDealer;

class Recharge
{
    private $model = null;
    private $dealer_id = 0;

    public function __construct($dealer_id)
    {
        $this->model = M('recharge_log');
        $this->dealer_id = $dealer_id;
    }

    /**
     * 创建充值记录
     * @param $data
     * @return bool|mixed
     */
    public function create($data)
    {
        if ($this->dealer_id < 1 || empty($data['order_no']) || (int)$data['pay_type'] < 1) {
            return false;
        }
        $data['create_time'] = date("Y-m-d H:i:s");
        $last_id = $this->model->add($data);
        return $last_id;
    }

    /**
     * 通过单号更新记录
     */
    public static function upByOrderNo($order_no, $data)
    {
        if(empty($order_no)){
            return false;
        }
        $map = array('order_no'=>$order_no);
        return M('recharge_log')->where($map)->save($data);
    }

    /**
     * 获取记录by单号
     */
    public static function getByOrderNo($order_no)
    {
        if(empty($order_no)){
            return false;
        }
        $map = array('order_no'=>$order_no);
        return M('recharge_log')->where($map)->find();
    }

    /**
     * 获取记录by transaction_id
     */
    public static function getByOrderTransactionId($transaction_id)
    {
        $map = array('transaction_id'=>$transaction_id);
        return M('recharge_log')->where($map)->find();
    }
}